package com.shengzai.sql

import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}

object Demo4Submit {
  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession.builder()
      .config("spark.sql.shuffle.partitions", 1)
      .appName("submit")
      .getOrCreate()

    val stuInfo: DataFrame = spark.read
      .format("csv")
      .option("sep", ",")
      .schema("id string ,name string ,age int ,sex string,clazz string")
      .load("/data/hive/student1000.txt")

    import org.apache.spark.sql.functions._
    import spark.implicits._
    val resDF: DataFrame = stuInfo.groupBy($"clazz")
      .agg(count("*"))

    resDF.write
      .format("csv")
      .mode(SaveMode.Overwrite)
      .option("sep",",")
      .save("/data/hive/sparkApi")

  }

}
